import javax.swing.*;
import java.beans.*;
import java.util.*;
import java.util.Observer;
import java.util.Observable;
import java.sql.*; 
import java.lang.*;

public class PrestarMaterial extends Observable implements Observer {
	
	 // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton16;
    private javax.swing.JButton jButton17;
    private javax.swing.JButton jButton18;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel41;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField11;
    private javax.swing.JTextField jTextField15;
    private javax.swing.JTextField jTextField16;
    private javax.swing.JTextField jTextField17;
    private javax.swing.JTextField jTextField18;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    private java.awt.Label label1;
    // End of variables declaration//GEN-END:variables
	JFrame ventanaPrestarMaterial;
	
	M_Prestatario prestatario;
	M_Volumen volumen;
	M_Material material;
	M_Prestamo prestamo;
	M_Configuraciones config;
	M_Multa multa;
	String seleccionado;
	boolean esPrestable;
	
		//variables de fecha de hoy
	int dia;
	int mes;
	int ao;
	Calendar fecha;
	String fechaHoy;
	
	//variables de la fecha en que se realizo el prestamo
	int diaP;
	int mesP;
	int aoP;
	
  	//otras variables
  	int diasMultaTotal;
    boolean atraso;
    int diaDevOficial;
	int diaDevReal;
	int diasAtraso;
	
	
	
     public PrestarMaterial() {
     	prestatario=new M_Prestatario();
		volumen=new M_Volumen();
		material=new M_Material();
		prestamo=new M_Prestamo();
		config=new M_Configuraciones();
        levantaVista();
        compruebaTipoSeleccionado();
		config.getDatos();
		
        jTextField7.setText(Integer.toString(config.diasPrestamo));
        
        
    }
    

    private void levantaVista() {
        ventanaPrestarMaterial=new JFrame();
          jPanel8 = new javax.swing.JPanel();
        jButton13 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jButton15 = new javax.swing.JButton();
        jButton16 = new javax.swing.JButton();
        jButton17 = new javax.swing.JButton();
        jButton18 = new javax.swing.JButton();
        label1 = new java.awt.Label();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jTextField6 = new javax.swing.JTextField();
        jTextField7 = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jPanel7 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel37 = new javax.swing.JLabel();
        jLabel38 = new javax.swing.JLabel();
        jLabel39 = new javax.swing.JLabel();
        jTextField16 = new javax.swing.JTextField();
        jLabel40 = new javax.swing.JLabel();
        jTextField17 = new javax.swing.JTextField();
        jLabel41 = new javax.swing.JLabel();
        jTextField18 = new javax.swing.JTextField();
        jButton12 = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jLabel33 = new javax.swing.JLabel();
        jLabel34 = new javax.swing.JLabel();
        jLabel35 = new javax.swing.JLabel();
        jLabel36 = new javax.swing.JLabel();
        jTextField15 = new javax.swing.JTextField();
        jButton10 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jComboBox3 = new javax.swing.JComboBox();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jTextField8 = new javax.swing.JTextField();
        jTextField9 = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jButton6 = new javax.swing.JButton();
        jTextField10 = new javax.swing.JTextField();
        jTextField11 = new javax.swing.JTextField();
        jComboBox4 = new javax.swing.JComboBox();
        jButton5 = new javax.swing.JButton();
        llenaComboBox();
        
        
		
        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(ventanaPrestarMaterial.getContentPane());
        ventanaPrestarMaterial.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        ventanaPrestarMaterial.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        ventanaPrestarMaterial.setResizable(false);
        ImageIcon icon = new ImageIcon("images/administrator1_16x16.gif");
        jButton13.setIcon(icon);
        jButton13.setText("Prestatario");
        jButton13.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton13.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jButton13.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });

        ImageIcon icon1 = new ImageIcon("images/report2_16x16.gif");
        jButton14.setIcon(icon1);
        jButton14.setText("Material");
        jButton14.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton14.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jButton14.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });

        ImageIcon icon2 = new ImageIcon("images/search_16x16.gif");
        jButton15.setIcon(icon2);
        jButton15.setText("Buscar");
        jButton15.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton15.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jButton15.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton15ActionPerformed(evt);
            }
        });

        ImageIcon icon3 = new ImageIcon("images/settings1_16x16.gif");
        jButton16.setIcon(icon3);
        jButton16.setText("Configuraci\u00f3n");
        jButton16.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton16.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jButton16.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton16.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton16ActionPerformed(evt);
            }
        });

        ImageIcon icon4 = new ImageIcon("images/ordered_list_16x16.gif");
        jButton17.setIcon(icon4);
        jButton17.setText("Multas en curso");
        jButton17.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton17.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jButton17.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton17.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton17ActionPerformed(evt);
            }
        });

        ImageIcon icon5 = new ImageIcon("images/script_(start)_16x16.gif");
        jButton18.setIcon(icon5);
        jButton18.setText("Prestamos en curso");
        jButton18.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton18.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jButton18.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton18.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton18ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton15)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton17)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton18)
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
                .addContainerGap(22, Short.MAX_VALUE)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                       .addComponent(jButton13)
                        .addComponent(jButton14)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton15)
                        .addComponent(jButton16)
                        .addComponent(jButton17)))
                    .addComponent(jButton18)))
        );
          ventanaPrestarMaterial.pack();
        ventanaPrestarMaterial.setVisible(true);

        label1.setFont(new java.awt.Font("Dialog", 1, 12));
        label1.setText("Ventana Material");

        jTabbedPane1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jLabel6.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setText("Prestamo de material");

        jLabel9.setText("Ingrese el RUT del prestatario:");

        jLabel10.setText("-");

        jLabel11.setText("Ingrese el codigo unico del volumen a prestar:");

        jLabel12.setText("Ingrese el numero de dias de duraci\u00f3n:");

        jLabel13.setText("Nota: Opcion disponible solo si el material puede ser prestado fuera del colegio");

        jLabel14.setText("Ingrese el numero de copias que se prestaran:");

        jLabel15.setText("Nota: opcion disponible solo para materiales de consulta.");
		
		
		ImageIcon botonprestar = new ImageIcon("images/ok_16x16.gif");
        jButton4.setIcon(botonprestar);
        jButton4.setText("Prestar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(273, 273, 273)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jTextField6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
                            .addComponent(jTextField7, javax.swing.GroupLayout.Alignment.TRAILING)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel9))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel11))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel12))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel13))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 548, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel14))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel15)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(244, Short.MAX_VALUE)
                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(212, 212, 212))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(77, Short.MAX_VALUE)
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 422, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(69, 69, 69))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jLabel6)
                .addGap(36, 36, 36)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addComponent(jLabel13)
                .addGap(22, 22, 22)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(15, 15, 15)
                .addComponent(jLabel14)
                .addGap(21, 21, 21)
                .addComponent(jLabel15)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
                .addComponent(jButton4)
                .addGap(29, 29, 29))
        );
          ventanaPrestarMaterial.pack();
        ventanaPrestarMaterial.setVisible(true);
        
        	ImageIcon tab1icon = new ImageIcon("images/table_(edit)_16x16.gif");
        
        jTabbedPane1.addTab("Prestamo",tab1icon, jPanel3);

        jLabel7.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel7.setText("Renovar Material");

        jLabel37.setText("Ingrese el codigo unico del volumen que desea renovar y el rut del prestatario.");

        jLabel38.setText("Si no desea hacer nada presione el bot\u00f3n \"Volver\"");

        jLabel39.setText("RUT del prestatario");

        jLabel40.setText("-");

        jLabel41.setText("C\u00f3digo \u00fanico del volumen");
		
		jButton12.setIcon(botonprestar);
        jButton12.setText("Renovar");
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel37))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel38))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel39, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTextField16, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel40)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField17, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(180, Short.MAX_VALUE))
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel41, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(437, 437, 437))
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField18, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(440, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addContainerGap(253, Short.MAX_VALUE)
                .addComponent(jButton12)
                .addGap(242, 242, 242))
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGap(60, 60, 60)
                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 422, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(86, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addGap(22, 22, 22)
                .addComponent(jLabel37)
                .addGap(19, 19, 19)
                .addComponent(jLabel38)
                .addGap(44, 44, 44)
                .addComponent(jLabel39)
                .addGap(14, 14, 14)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField16, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel40, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField17, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addComponent(jLabel41)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField18, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(37, 37, 37)
                .addComponent(jButton12)
                .addContainerGap(112, Short.MAX_VALUE))
        );
          ventanaPrestarMaterial.pack();
        ventanaPrestarMaterial.setVisible(true);
        
        	ImageIcon tab2icon = new ImageIcon("images/table_(add)_16x16.gif");
        
        jTabbedPane1.addTab("Renovar",tab2icon, jPanel7);

        jPanel6.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jLabel33.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel33.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel33.setText("Devolver Material");

        jLabel34.setText("Ingrese el codigo unico del volumen que desea eliminar.");

        jLabel35.setText("Si no desea hacer nada, presione el boton \"Volver\".");

        jLabel36.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel36.setText("ID UNICO:");
	   
	   
       jButton10.setIcon(botonprestar);
       jButton10.setText("Devolver");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel35)
                    .addComponent(jLabel34))
                .addContainerGap(256, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(233, Short.MAX_VALUE)
                .addComponent(jButton10)
                .addGap(218, 218, 218))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(215, Short.MAX_VALUE)
                .addComponent(jTextField15, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(195, 195, 195))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(81, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel33, javax.swing.GroupLayout.PREFERRED_SIZE, 409, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel36, javax.swing.GroupLayout.PREFERRED_SIZE, 409, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(72, 72, 72))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel33)
                .addGap(32, 32, 32)
                .addComponent(jLabel34)
                .addGap(16, 16, 16)
                .addComponent(jLabel35)
                .addGap(36, 36, 36)
                .addComponent(jLabel36)
                .addGap(16, 16, 16)
                .addComponent(jTextField15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41)
                .addComponent(jButton10)
                .addGap(146, 146, 146))
        );
          ventanaPrestarMaterial.pack();
        ventanaPrestarMaterial.setVisible(true);
        
        	ImageIcon tab3icon = new ImageIcon("images/report2_(delete)_16x16.gif");
        
        jTabbedPane1.addTab("Devolver",tab3icon, jPanel6);

        jLabel16.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel16.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel16.setText("Agregar un nuevo material");

        jLabel17.setText("Ingrese los datos del nuevo material y presione \"Ingresar Material\".");

        jLabel18.setText("Si desea salir, presione el boton Cancelar");

        jLabel19.setText("Tipo de material:");

        jLabel20.setText("Nombre:");

        jLabel21.setText("Descripcion:");

        jLabel22.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel22.setText("Informacion para libros, enciclopedias, etc.");

        jLabel23.setText("Titulo:");

        jLabel24.setText("Autor:");

        jLabel25.setText("Clasificacion Tematica:");
		
		
        jButton6.setIcon(botonprestar);
        jButton6.setText("Ingresar Material");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel18)
                                    .addComponent(jLabel17))
                                .addContainerGap(234, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel19)
                                    .addComponent(jLabel20)
                                    .addComponent(jLabel21))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 195, Short.MAX_VALUE)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jPanel4Layout.createSequentialGroup()
                                        .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jTextField8)
                                            .addComponent(jComboBox3, 0, 197, Short.MAX_VALUE))
                                        .addGap(86, 86, 86))))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel22)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(81, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel23)
                                    .addComponent(jLabel24)
                                    .addComponent(jLabel25))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 169, Short.MAX_VALUE)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jComboBox4, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jTextField11)
                                    .addComponent(jTextField10, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE))
                                .addGap(85, 85, 85)))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                            .addComponent(jButton6)
                            .addGap(217, 217, 217)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel16)
                        .addGap(202, 202, 202))))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel16)
                .addGap(23, 23, 23)
                .addComponent(jLabel17)
                .addGap(22, 22, 22)
                .addComponent(jLabel18)
                .addGap(22, 22, 22)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(16, 16, 16)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel22))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel23)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel24)
                        .addGap(17, 17, 17)
                        .addComponent(jLabel25))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(15, 15, 15)
                .addComponent(jButton6)
                .addGap(24, 24, 24))
        );
          ventanaPrestarMaterial.pack();
        ventanaPrestarMaterial.setVisible(true);
        
        	ImageIcon tab4icon = new ImageIcon("images/report2_(add)_16x16.gif");
        
        jTabbedPane1.addTab("Agregar",tab4icon, jPanel4);
		
		ImageIcon volvericon = new ImageIcon("images/left_16x16.gif");
        jButton5.setIcon(volvericon);
        jButton5.setText("Volver");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(ventanaPrestarMaterial.getContentPane());
        ventanaPrestarMaterial.getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(306, Short.MAX_VALUE)
                .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(246, 246, 246))
            .addGroup(layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(40, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(297, Short.MAX_VALUE)
                .addComponent(jButton5)
                .addGap(292, 292, 292))
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(27, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                .addComponent(jButton5)
                .addContainerGap())
        );
        
          ventanaPrestarMaterial.pack();
        ventanaPrestarMaterial.setVisible(true);
        ventanaPrestarMaterial.pack();
    
    }
    
	//verifica si el material es prestable fuera del colegio
	private void compruebaTipoMaterial(String codigoVolumen){
	esPrestable=material.esPrestable;	
	}
	//verifica si existe el prestatario	
	private boolean existePrestatario(String rutPrestatario){
		
		return prestatario.existeRut(rutPrestatario);	
	}
	//verifica si existe el volumen indicado	
	private boolean existeVolumen(String codigoVolumen){
		try{
		Integer.parseInt(jTextField6.getText());
		if(jTextField6.getText().equals("")==false){
			return volumen.existeVolumen(codigoVolumen);
		}
		return false;
		}catch(Exception e){return false;}	}
	
	//verifica si hay stock	
	private boolean verificarStock(String codigoVolumen){
		volumen.getDatosVolumen(volumen.mat_cod, volumen.vol_cod);
		if(material.verificarStock(volumen.mat_cod) && volumen.vol_disponible.equals("DISPONIBLE"))
		return true;
		
		
		return false;
	}
	
	//verifica si el prestatario no tiene prestamos en curso	
	//AL DIA
	//PRESTAMO EN CURSO
	//MULTADO
	//SUSPENDIDO
	//PRESTAMO MASIVO EN CURSO
	private boolean verificaPrestabilidad(String rutPrestatario){
		prestatario.getDatos(rutPrestatario);
		if(prestatario.prt_prestamosEnCurso_int>config.prestamosMax){
			return false;
		}
		if(prestatario.prt_situacionActual.equals("MULTADO")||prestatario.prt_situacionActual.equals("PRESTAMO MASIVO EN CURSO") || prestatario.prt_situacionActual.equals("SUSPENDIDO") ){
			return false;
			
		}
		
		
		return true;
		
		
	}
	
	//actualiza estados del prestatario y del volumen	
	private void actualizarEstados(String codigoVolumen, String rutPrestatario){
		if(esPrestable){
			volumen.actualizaEstadoAPrestado();
			prestatario.setSituacionActual(rutPrestatario,"PRESTAMO EN CURSO");
			prestatario.subirPrestamosEnCurso(rutPrestatario);
			System.out.println("actualizandoEstadosYSTOCK");
		}else{
			
			
		}
		
	}
	
	//actualiza stock	
	private void actualizarStockMaterial(String codigoVolumen){
		material.restaDisponibles(volumen.mat_cod);
	}
	
	//verifica si existe	
	private void registrarPrestamo(){
		
		prestamo.prestarMaterial(prestatario.prt_cod,volumen.vol_cod, Integer.parseInt(jTextField7.getText()));
		JOptionPane.showMessageDialog(ventanaPrestarMaterial,
    							"El prestamo se ha realizado exitosamente.\n Prestatario: "+prestatario.prt_nombres +" "+prestatario.prt_apellidos+".\nVolumen Prestado: "+material.mat_nombre+" / "+material.mat_titulo+" .",
    							"Aviso",
    							JOptionPane.INFORMATION_MESSAGE);
  		System.out.println("prestamoRealizaddo");
    	this.setChanged();
		this.notifyObservers(); 
		ventanaPrestarMaterial.dispose();
		
	}
	
public static void main(String args[]) {
      PrestarMaterial e=new PrestarMaterial();
    }
    
    
    
    
    //renovar
    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {                                         
	if(verificarIdVolumen(jTextField18.getText())){
		
		if(existePrestatario(jTextField16.getText()+"-"+jTextField17.getText())){
			getPrestamo();
				if(prestamoAlDia()){
					if(verificarRenovaciones()){
						if(JOptionPane.showConfirmDialog(ventanaPrestarMaterial,"Esta seguro que desea renovar este prestamo?","Consulta",JOptionPane.YES_NO_OPTION) == 0) {
						actualizarDatos();
							JOptionPane.showMessageDialog(ventanaPrestarMaterial,
	    						"La renovacion ha sido llevada a cabo correctamente.",
	    						"Aviso",
	    						JOptionPane.INFORMATION_MESSAGE);
	    					jTextField16.setText("");
	    					jTextField18.setText("");
	    					jTextField17.setText("");	
	    						
					}else{
					JOptionPane.showMessageDialog(ventanaPrestarMaterial,
	    						"La renovacion no ha sido llevada a cabo.",
	    						"Aviso",
	    						JOptionPane.INFORMATION_MESSAGE);	
					}
						
					}else{
					JOptionPane.showMessageDialog(ventanaPrestarMaterial,
	    						"El numero maximo de renovaciones ha sido alcanzado. No se puede volver a renovar..",
	    						"Aviso",
	    						JOptionPane.INFORMATION_MESSAGE);	
						
					}
					
				}else{
				JOptionPane.showMessageDialog(ventanaPrestarMaterial,
	    						"El prestatario indicado no puede renovar debido a que esta atrasado en la devolucion del volumen.",
	    						"Aviso",
	    						JOptionPane.INFORMATION_MESSAGE);	
				}
			
			
		}else{
			JOptionPane.showMessageDialog(ventanaPrestarMaterial,
	    						"El prestatario indicado no existe o el rut no esta escrito correctamente.",
	    						"Aviso",
	    						JOptionPane.INFORMATION_MESSAGE);
			
		}
		
	}else{
		JOptionPane.showMessageDialog(ventanaPrestarMaterial,
	    						"El volumen indicado no existe o no esta actualmente en prestamo.",
	    						"Aviso",
	    						JOptionPane.INFORMATION_MESSAGE);
	}

    } 
    
    
    
    
    
    
//   prestar
 private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
	
		if(existeVolumen(jTextField6.getText())){
			System.out.println("CHECKPOINT 1");
			if(existePrestatario(jTextField4.getText()+"-"+jTextField5.getText())){
				System.out.println("CHECKPOINT 2");
				if(verificarStock(jTextField6.getText())){
						System.out.println("CHECKPOINT 3");
					if(verificaPrestabilidad(jTextField4.getText()+"-"+jTextField5.getText())){
						System.out.println("CHECKPOINT 4");
						compruebaTipoMaterial(jTextField6.getText());
						
							if(esPrestable){
								System.out.println("CHECKPOINT 5");
								try{
									int e=Integer.valueOf(jTextField7.getText()).intValue();
								String consulta;
								if(volumen.vol_reservado_a.equals("NO RESERVADO"))
								consulta="¿Esta seguro que desea prestar este volumen por "+jTextField7.getText()+" dias?";
								else
								consulta="Este volumen esta reservado a "+volumen.vol_reservado_a+ ".\n¿Esta seguro que desea prestar este volumen por "+jTextField7.getText()+" dias?";
								
								if(JOptionPane.showConfirmDialog(ventanaPrestarMaterial,consulta,"Consulta",JOptionPane.YES_NO_OPTION) == 0) {
									volumen.reservar(volumen.vol_cod, "NO RESERVADO");
									System.out.println("CHECKPOINT 6");
									actualizarEstados(jTextField6.getText(),jTextField4.getText()+"-"+jTextField5.getText());
									actualizarStockMaterial(jTextField6.getText());
		 							registrarPrestamo();
								
								}else{JOptionPane.showMessageDialog(ventanaPrestarMaterial,
    							"El prestamo no se ha llevado a cabo.",
    							"Aviso",
    							JOptionPane.INFORMATION_MESSAGE);	}
									
								}catch(NumberFormatException e){
								JOptionPane.showMessageDialog(ventanaPrestarMaterial,
    							"El numero de dias ingresado no esta escrito correctamente.\nEl prestamo no puede ser llevado a cabo.",
    							"Aviso",
    							JOptionPane.INFORMATION_MESSAGE);	
								}
							
							
												 	
							}else{	
								JOptionPane.showMessageDialog(ventanaPrestarMaterial,
    							"Este material no puede ser sacado de la biblioteca, El prestamo no se ha llevado a cabo.",
    							"Aviso",
    							JOptionPane.INFORMATION_MESSAGE);	
    							}
						}else{
						JOptionPane.showMessageDialog(ventanaPrestarMaterial,
    					"El prestatario indicado no puede pedir materiales.\nVerifique que no esta multado o que no ha exedido el numero maximo de prestamos.\nEl prestamo no puede ser llevado a cabo.",
    					"Aviso",
    					JOptionPane.INFORMATION_MESSAGE);
						
						}
					
					
				}else{
					JOptionPane.showMessageDialog(ventanaPrestarMaterial,
    			"El volumen indicado no tiene stock o está prestado.\nEl prestamo no puede ser llevado a cabo.",
    			"Aviso",
    			JOptionPane.INFORMATION_MESSAGE);
					
				}
	
	    	}else{
	    		JOptionPane.showMessageDialog(ventanaPrestarMaterial,
    			"El prestatario indicado no existe o el rut esta mal escrito.\nEl prestamo no puede ser llevado a cabo.",
    			"Aviso",
    			JOptionPane.INFORMATION_MESSAGE);
	    	}
	    
	    }else{
	    	JOptionPane.showMessageDialog(ventanaPrestarMaterial,
    		"El volumen indicado no existe o el codigo esta mal escrito.\nEl prestamo no puede ser llevado a cabo.",
    		"Aviso",
    		JOptionPane.INFORMATION_MESSAGE);
	    }
    }
    
    
    
    //Agregar
    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {

	if(seleccionado.equals("libro")){
		if(jTextField8.getText().length()>3||jTextField9.getText().length()>3||jTextField10.getText().length()>3||jTextField11.getText().length()>3){
			if(JOptionPane.showConfirmDialog(
	   	 	ventanaPrestarMaterial,
	   	 	"Esta seguro que desea agregar este material?",
	  	  	"Consulta",
	   	 	JOptionPane.YES_NO_OPTION) == 0) {
			    material.agregarMaterial(material.idTiposMateriales[jComboBox3.getSelectedIndex()],material.idTematicasMateriales[jComboBox4.getSelectedIndex()], jTextField8.getText(), jTextField10.getText(), jTextField11.getText(), jTextField9.getText());
				JOptionPane.showMessageDialog(ventanaPrestarMaterial,
			    "El material ha sido agregado exitosamente",
			    "Aviso",
			    JOptionPane.INFORMATION_MESSAGE);
		    
		    	limpiarCampos();
	    	}
		}else{
			JOptionPane.showMessageDialog(ventanaPrestarMaterial,
			    "Los valores ingresados son muy cortos. Revise que esten escritos correctamente.",
			    "Aviso",
			    JOptionPane.INFORMATION_MESSAGE);
		}	
	
    
	}else{
		if(jTextField8.getText().length()>3||jTextField9.getText().length()>3){
		
		if(JOptionPane.showConfirmDialog(
	    ventanaPrestarMaterial,
	    "Esta seguro que desea agregar este material?",
	    "Consulta",
	    JOptionPane.YES_NO_OPTION) == 0) {
		    material.agregarMaterial(material.idTiposMateriales[jComboBox3.getSelectedIndex()],jTextField8.getText(), jTextField9.getText());
			JOptionPane.showMessageDialog(ventanaPrestarMaterial,
		    "El material ha sido agregado exitosamente",
		    "Aviso",
		    JOptionPane.INFORMATION_MESSAGE);
		    
		    limpiarCampos();
    	}
  		}else{
			JOptionPane.showMessageDialog(ventanaPrestarMaterial,
			    "Los valores ingresados son muy cortos. Revise que esten escritos correctamente.",
			    "Aviso",
			    JOptionPane.INFORMATION_MESSAGE);
		}
    
    
    
	}
    }
    
    
    //devolver
    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {                                         
		if(verificarIdVolumen(jTextField15.getText())){
					if(JOptionPane.showConfirmDialog(ventanaPrestarMaterial,"Esta seguro que desea devolver este volumen?","Consulta",JOptionPane.YES_NO_OPTION) == 0) {
						getPrestamo();
						verificaMulta();
						if(atraso){
							JOptionPane.showMessageDialog(ventanaPrestarMaterial,
	    						"El volumen ha sido devuelto con un retraso de "+diasAtraso+" dias.\nEl prestatario esta impedido de pedir libros durante los proximos "+diasMultaTotal+" dias.",
	    						"Aviso",
	    						JOptionPane.INFORMATION_MESSAGE);
						
						}
						actualizaEstados();
							JOptionPane.showMessageDialog(ventanaPrestarMaterial,
	    						"El volumen ha sido devuelto correctamente.",
	    						"Aviso",
	    						JOptionPane.INFORMATION_MESSAGE);
							jTextField15.setText("");
					}else{
						JOptionPane.showMessageDialog(ventanaPrestarMaterial,
	    					"La devolucion no se ha llevado a cabo.",
	    					"Aviso",
	    					JOptionPane.INFORMATION_MESSAGE);
					
					}
								
		
    	}else{
    				JOptionPane.showMessageDialog(ventanaPrestarMaterial,
    					"El volumen indicado no existe o no est en prestamo.\nVerifique que el codigo esta bien escrito o que el volumen efectivamente est prestado.\nLa devolucion no puede ser llevada a cabo.",
    					"Aviso",
    					JOptionPane.INFORMATION_MESSAGE);	
    		
    	}
    }             
    
    
    
    
    
    
    
    
    
    
    
    /* Funciones de Renovar Material*/
    
     //verificar existencia del rut y del volumen
    //verificar que esta en prestamo
    public boolean verificarIdVolumen(String id){
    	if(id.length()==11){
    	if (volumen.existeVolumen(id)){
    		if(volumen.estaEnPrestamo()){
    		return true;
    		}else{ 
    			return false;
    		}
    		
    	}else{
    		return false;
    	}
    	
		}else{
			return false;
		}    
    }
    
    
	//verificar que el prestamo esta al dia
	
	
    public void getPrestamo(){
    	prestamo.getPrestamo(volumen.vol_cod);
    	
    }
    
    public boolean prestamoAlDia(){
    	if(prestamo.prestamo_estado.equals("PRESTAMO EN CURSO")||prestamo.prestamo_estado.equals("EN CURSO RENOVADO"))
    	return true;
    	else
    	return false;
    }
    //verificar que el numero de renovaciones no pasa el maximo
    //no usar antes de verificar id volumen
    public boolean verificarRenovaciones(){
    	prestamo.getPrestamo(volumen.vol_cod);
    	if(volumen.vol_contador_renovaciones< config.renovacionesMax)
    	return true;
    	else
    	return false;
    	
    }
    
	//actualizar fecha de prestamo
	//actualizar contador de renovaciones
	public void actualizarDatos(){
			
	Calendar fecha=Calendar.getInstance();
	int ao= fecha.get(fecha.YEAR);
	int mes= fecha.get(fecha.MONTH)+1;
	int dia= fecha.get(fecha.DAY_OF_MONTH);
	
	//actualizar fecha de prestamo
	String f=ao+"-"+mes+"-"+dia;
	prestamo.actualizarFecha(f,volumen.mat_cod);
	//actualizar contador de renovaciones	
	volumen.actualizaContadorRenovaciones(volumen.vol_contador_renovaciones+1);	
	}
    
    
    
    
    /* Funciones de Agregar Material*/
    
    
    	private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt){
		System.out.println("lala");
		compruebaTipoSeleccionado();
	
		
		}  
		
	public void compruebaTipoSeleccionado(){
			if(material.tiposMaterialesInfo[jComboBox3.getSelectedIndex()] ==0){
			jTextField10.setEnabled(false);
			jTextField11.setEnabled(false);
			jComboBox4.setEnabled(false);
			seleccionado = "otro";
		}
			if(material.tiposMaterialesInfo[jComboBox3.getSelectedIndex()] ==1){
			jTextField10.setEnabled(true);
			jTextField11.setEnabled(true);
			jComboBox4.setEnabled(true);
			seleccionado="libro";
		}
	}	  
	
	private void llenaComboBox(){
	try{
		
	material.getTiposMateriales();

	material.getCategorias();

	for(int i=0;i<material.numeroTiposMateriales;i++){
    	jComboBox3.insertItemAt(material.tiposMateriales[i],i);
    	System.out.println(material.tiposMateriales[i]);
    	
    }
    
    	for(int i=0;i<material.numeroTematicasMateriales;i++){
    	jComboBox4.insertItemAt(material.tematicasMateriales[i],i);
    	System.out.println(material.tematicasMateriales[i]);
    	
    }
    
    }catch(Exception e){}
    
    jComboBox3.setSelectedIndex(0);
	jComboBox4.setSelectedIndex(0);
}

private void limpiarCampos(){
	jTextField8.setText("");
	jTextField9.setText("");
	jTextField10.setText("");
	jTextField11.setText("");
	jComboBox3.setSelectedIndex(0);
	jComboBox4.setSelectedIndex(0);
}
   
    
    
    /*Funciones de Devolver Material*/
    
    
    //verifica si existe el volumen y si esta en prestamo
    public boolean verificarIdVolumen2(String id){
    	if(id.length()==11){
    	if (volumen.existeVolumen(id)){
    		if(volumen.estaEnPrestamo()){
    		return true;
    		}else{ 
    			return false;
    		}
    		
    	}else{
    		return false;
    	}
    	
		}else{
			return false;
		}    
    }
    

    /*//Obtiene los datos del prestamo a partir del id del volumen 
    public void getPrestamo2(){
    	prestamo.getPrestamo(volumen.vol_cod);
    	
    }*/
    
    //verifica si hay multa en curso por atraso y calcula los dias de multa que seran aplicados
  	public void verificaMulta(){
  		if(prestamo.mul_codigo!=0){
  		//hay multa
  		multa.getDatosMulta(prestamo.mul_codigo);
  		calcularDiasMulta();
  		atraso=true;	
  		}else{
  			atraso=false;
  		}
  		
  	}
  
    public void actualizaEstados(){
    fecha=Calendar.getInstance();
	ao= fecha.get(fecha.YEAR);
	mes= fecha.get(fecha.MONTH)+1;
    dia=fecha.get(fecha.DAY_OF_MONTH);
    //estados del prestamo
    fechaHoy=ao+"-"+mes+"-"+dia;
    if(atraso){
   
    prestamo.actualizarEstados(fechaHoy,"ATRASO", "DEVOLUCION ATRASADA");
     }else{
     
    prestamo.actualizarEstados(fechaHoy,"AL DIA", "TERMINADO");
    }
    //estados de la multa
    if(atraso){
   
    multa.actualizaDatosMulta(diasAtraso,fechaHoy,diasMultaTotal, "MULTA EN EJECUCION");
    } 
    //estados del material
    material.aumentaDisponibles(volumen.mat_cod);
    material.restaPrestados(volumen.mat_cod);
    //estados del volumen
    volumen.actualizaEstadoADisponible();
    volumen.actualizaContadorRenovaciones(0);
    //estados del prestatario
    prestatario.getDatos(prestamo.prestatario_codigo);
    prestatario.bajarPrestamosEnCurso();
    if(atraso){
    
    prestatario.setSituacionActual(prestatario.prt_rut,"MULTADO");
    }else{
    
    prestatario.setSituacionActual(prestatario.prt_rut,"AL DIA");
    }	
    }               

	//calcula dias de multa de la multa en proceso
	public void calcularDiasMulta(){
		fecha=Calendar.getInstance();
		ao= fecha.get(fecha.YEAR);
		mes= fecha.get(fecha.MONTH)+1;
		int diaA= fecha.get(fecha.DAY_OF_MONTH);
		dia=fecha.get(fecha.DAY_OF_MONTH);
		separaStringFecha(prestamo.fecha_prestamo);
		
		if (mes!=mesP){
			if(mes==3 || mes==5 ||mes==7|| mes==8 || mes==10 ||mes==12){
			diaA=diaA+31;
			 
			}if(mes==4 || mes==6 || mes==9 || mes==11){
			diaA=diaA+30;
			
		}
		}
		diaDevOficial=diaP+prestamo.pre_duracion;
		diaDevReal=diaA;
		diasAtraso=diaDevReal-diaDevOficial;
		config.getDatos();
		diasMultaTotal=diasAtraso*config.diasMultaPorAtraso;
		System.out.println(diasAtraso+"   "+config.diasMultaPorAtraso+"   "+diasMultaTotal);
		multa.multa_duracion=diasMultaTotal;
		
		
	}
	

	public void separaStringFecha(String fecha_prestamo){

	mesP=0;
	diaP=0;
	aoP= Integer.parseInt(fecha_prestamo.substring(0,4));
	
	try{
	
		mesP= Integer.parseInt(fecha_prestamo.substring(5,7));
		try{
			diaP= Integer.parseInt(fecha_prestamo.substring(8,10));
		}
		catch(Exception e){
			diaP= Integer.parseInt(fecha_prestamo.substring(8,9));
		}
	
	}catch(Exception e){
		 mesP= Integer.parseInt(fecha_prestamo.substring(5,6));
		 try{
			diaP= Integer.parseInt(fecha_prestamo.substring(7,9));
		 }
		 catch(Exception l){
			diaP= Integer.parseInt(fecha_prestamo.substring(7,8));
		 }
	}
	 
	System.out.println(aoP+" "+mesP+" "+diaP);
	
}
    
    
    
    
    
    
    
    
    
	//volver
    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
		this.setChanged();
		this.notifyObservers(); 
		ventanaPrestarMaterial.dispose();
    }
	//buscar material
  //  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

//    }
    
    
  private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton18ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jButton18ActionPerformed

    private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton17ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jButton17ActionPerformed

    private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton16ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jButton16ActionPerformed

    private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton15ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jButton15ActionPerformed

    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jButton14ActionPerformed

    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jButton13ActionPerformed
	

	
	public void update( Observable obs,Object obj) {
     
      	ventanaPrestarMaterial.setVisible(true);
   
      
      
      }


}